extern crate proc_macro;

mod derive_enum_ext;
mod page_builder;

use proc_macro::TokenStream;

/**
 * 构建分页查询方法
 */
#[proc_macro_derive(QueryPageBuilder)]
pub fn derive_query_page_builder_fn(input: TokenStream) -> TokenStream {
    page_builder::derive_fn(input)
}

/// 使用 `axum_app_macro::EnumExt` 扩展宏来为枚举添加额外属性。
/// ```rust
///
///  use axum_app_macro::EnumExt;
///
/// #[derive(Debug, EnumExt)]
/// pub enum Status {
///     #[attrs(label = "激活", code = "ACTIVE")]
///     Active,
///     #[attrs(label = "未激活")]
///     Inactive,
/// }
///
/// #[test]
/// fn test_enum_ext() {
///     let label = Status::Active.label();
///     assert_eq!("激活", label.as_str());
///
///     let code = Status::Inactive.code();
///     assert_eq!("Inactive", code.as_str());
///
///     let code = Status::Active.code();
///     assert_eq!("ACTIVE", code.as_str());
///
///     let json = Status::Active.to_json();
///     assert_eq!(r#"{ "code": "ACTIVE", "name": "Active", "label": "激活" }"#,json.as_str());
/// }
///
/// ```
#[proc_macro_derive(EnumExt, attributes(attrs))]
pub fn derive_enum_ext_fn(input: TokenStream) -> TokenStream {
    derive_enum_ext::derive_fn(input)
}
